home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Applications / gdbm-1.7.3 / samp1.cc < prev    next >
C/C++ Source or Header  |  1994-05-21  |  921b  |  37 lines

  1. // small c++ to open store then close a gdbm file 
  2. // by Mike MacFaden 4/93  mike@premisys.com
  3. // tested with gdbm 1.5 and gnu v2.2 c++ compiler
  4.  
  5. #include "iostream.h"
  6. #include "gdbm.h"
  7.  
  8. extern int errno;        /* C runtime library */
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     cout << "Sample C++ program create a gdbm file ./tgdbm " << endl;
  13.  
  14.     GDBM_FILE pfile = gdbm_open("tstgdbm", 512, GDBM_WRCREAT, 00664, 0);
  15.     if (!pfile)
  16.       {
  17.       cout << "main:gdbm_open " << gdbm_errno << errno << endl;
  18.       return -1;
  19.       }
  20.  
  21.    datum key = {"foo", strlen("foo")+1};
  22.    datum val = {"bar", strlen("bar")+1};
  23.  
  24.     cout << "key is  : " << key.dptr << endl;
  25.     cout << "data is : " << val.dptr << endl;
  26.  
  27.    if (gdbm_store(pfile, key, val, GDBM_INSERT) != 0)
  28.       {
  29.       cout << "main:gdbm_store " << gdbm_errno << errno << endl;
  30.       return -1;
  31.       }
  32.     gdbm_close(pfile);
  33.  
  34.     cout << "Sample C++ program complete" << endl;
  35.     return 0;        
  36. }
  37.